package com.aishua.andpaydemo.activity;

import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.aishua.andpaydemo.R;
import com.aishua.andpaydemo.adapter.MessageAdapter;
import com.aishua.andpaydemo.adapter.ShopAdapter;
import com.aishua.andpaydemo.fragment.BaseFragment;
import com.aishua.andpaydemo.fragment.messagefragment.ShangjiaFragment;
import com.aishua.andpaydemo.fragment.messagefragment.XitongFragment;

import java.util.ArrayList;

/**
 * Created by aishua on 2018/5/18.
 */

public class MessageActivity extends BaseActivity implements View.OnClickListener {

    private ImageView img_title_xiaoxi;
    private TextView tv_title;
    private TextView tv_setting;
    private TabLayout tab_message;
    private ViewPager vp_message_content;
    private ArrayList<String> list_title;
    private ArrayList<BaseFragment> baseFragments;

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message);
        initTitleView();
        initView();
    }

    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    private void initTitleView() {

        tv_title = findViewById(R.id.tv_title);
        tv_setting = findViewById(R.id.tv_setting);
        img_title_xiaoxi = findViewById(R.id.img_title_xiaoxi);


        tv_title.setText("我的消息");
        tv_setting.setText("全标已读");
        img_title_xiaoxi.setBackground(getDrawable(R.drawable.back));
        img_title_xiaoxi.setOnClickListener(this);
    }


    private void initView() {

        vp_message_content = findViewById(R.id.vp_message_content);
        tab_message = findViewById(R.id.tab_message);

        //将名称加载tab名字列表，正常情况下，我们应该在values/arrays.xml中进行定义然后调用
        list_title = new ArrayList<>();
        list_title.add("系统推送");
        list_title.add("商家优惠");

        //设置TabLayout的模式
        tab_message.setTabMode(TabLayout.MODE_FIXED);
        //为TabLayout添加tab名称
//        tab_caifu.addTab(tab_caifu.newTab().setText(list_title.get(0)));
//        tab_caifu.addTab(tab_caifu.newTab().setText(list_title.get(1)));
//        tab_caifu.addTab(tab_caifu.newTab().setText(list_title.get(2)));

        initFragment();
        vp_message_content.setAdapter(new MessageAdapter(getSupportFragmentManager(), baseFragments, list_title));

        tab_message.setupWithViewPager(vp_message_content);
    }

    private ShangjiaFragment shangjiaFragment;
    private XitongFragment xitongFragment;

    public void initFragment() {

        baseFragments = new ArrayList<>();
        baseFragments.clear();

        xitongFragment = new XitongFragment();
        shangjiaFragment = new ShangjiaFragment();

        baseFragments.add(xitongFragment);
        baseFragments.add(shangjiaFragment);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.img_title_xiaoxi:

                finish();
                break;
        }
    }
}
